package model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * 
 * @author Sonny Sandberg
 */
public class CustomerName 
{
    private int id;
    private String name;
    private boolean mortician;
    private ArrayList<ActionListener> listeners;

    public CustomerName(int id, String name, boolean mortician)
    {
        this.id = id;
        this.name = name;
        this.mortician = mortician;
        listeners = new ArrayList();
        notifyListeners();
    }

    public CustomerName()
    {
        listeners = new ArrayList();
        reset();
    }
    
    public void reset()
    {
        id = 0;
        name = "";
        mortician = false;
        notifyListeners();
    }

    public int getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public boolean isMortician()
    {
        return mortician;
    }

    public void setId(int id)
    {
        this.id = id;
        notifyListeners();
    }

    public void setName(String name)
    {
        this.name = name;
        notifyListeners();
    }

    public void setMortician(boolean mortician)
    {
        this.mortician = mortician;
        notifyListeners();
    }
    
    public void clearModel()
    {
        id = 0;
        name = "";
        mortician = false;
        notifyListeners();
    }
    
    public boolean isCompleted()
    {
        boolean answer = false;
        
        if (name.length() > 0)
        {
            answer = true;
        }
        
        return answer;
    }
    
    @Override
    public String toString()
    {
        String toReturn = "";
        
        toReturn = String.format("ID: %d\n Name: %s\nBedemand: %b", id, name, mortician);
        
        return toReturn;
    }
    
    public void addListener(ActionListener listener) 
    {
        listeners.add(listener);
    }

    private void notifyListeners() 
    {
        ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Something changed");
        for (ActionListener listener : listeners) 
        {
            listener.actionPerformed(event);
        }
    }
}